var myCirclePlayer;
var currItemNumber;
var sermonList = [
	"../AUDIO/2009/CAMPMEETING%202009/4.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/9.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/7.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/11.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/13.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/16.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/18.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/22.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/24.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/26.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/29.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/32.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/09-27-09 Kevin noles Jeremiah 1;1-8.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/Bro Bud Stiltner Isaiah 59;16-19.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/19.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/9-27-09-Living proof.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/23.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/28.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/30.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/2.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/5.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/8.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/10.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/15.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/20.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/21.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/3.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/8.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/12.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/25.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/6.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/17.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/27.mp3",
	"../AUDIO/2009/CAMPMEETING%202009/31.mp3"
];

function selectItem(item) {
    if (0 <= currItemNumber && currItemNumber < sermonList.length) {
    	var currItem = document.getElementById("player-item-" + currItemNumber.toString());
        removeClass(currItem, 'bold');
        removeClass(currItem, 'colorPrimary-5');
        addClass(currItem, 'colorSecondary-a-2');
    }
    addClass(item, 'bold');
    addClass(item, 'colorPrimary-5');
    removeClass(item, 'colorSecondary-a-2');
    currItemNumber = parseInt(item.id.substr(item.id.lastIndexOf("-") + 1));
    myCirclePlayer.setMedia({
    	mp3: sermonList[currItemNumber]
    });
}

function playItem(item) {
    selectItem(item);
	myCirclePlayer.play();
}

function playNextItem() {
    var nextItemNumber = currItemNumber + 1;
    if (nextItemNumber < sermonList.length) {
        playItem(document.getElementById("player-item-" + nextItemNumber.toString()));
    }
}

$(document).ready(function(){
	myCirclePlayer = new CirclePlayer("#jquery_jplayer_1",
	{
	}, {
		supplied: "mp3",
		cssSelectorAncestor: "#cp_container_1",
		swfPath: "../Content/Javascript/jplayer/Jplayer.swf",
		wmode: "window",
		keyEnabled: true
	});

	$("#jquery_jplayer_1").bind($.jPlayer.event.ended, function (event) {
		if (currItemNumber < 13) {
        	playNextItem();
    	}
    });

	for(var i = 0; i < sermonList.length; ++i){
		addClass(document.getElementById("player-item-" + i.toString()), 'colorSecondary-a-2');
	}

	selectItem(document.getElementById("player-item-0"));
});
